home *** CD-ROM | disk | FTP | other *** search
- ;void box_right(box,col,row,width,depth);
- ; unsigned char *box,*col,*row,width,depth;
-
- EXTRN _memory_model:byte
- EXTRN _video_buffer:word
- EXTRN _snow_protect:byte
-
- box_seg EQU [bp-2]
- box_ofs EQU [bp-4]
- col_seg EQU [bp-6]
- col_ofs EQU [bp-8]
- row_seg EQU [bp-10]
- row_ofs EQU [bp-12]
- width EQU [bp-14]
- depth EQU [bp-16]
- snow EQU [bp-18]
- endofbox EQU [bp-20]
- toppos EQU [bp-22]
- rghtpos EQU [bp-24]
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _box_right
- _box_right proc near
- push bp ;
- mov bp,sp ;set stack frame
- sub sp,24 ;make room to hold parameters
- push di ;
- push si ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: push ds ;save Turbo's DS
- mov dx,_video_buffer ;grab _video_buffer
- mov bl,_snow_protect ;
- mov snow,bl ;save it
- cmp _memory_model,2 ;data near or far?
- jb L0 ;jump if near
- push [bp+6] ;move parameters to SP offsets
- push [bp+10]
- push [bp+14]
- push [bp+4]
- push [bp+8]
- push [bp+12]
- push [bp+16]
- push [bp+18]
- jmp short L00
- L0: push ds ;near case
- push ds
- push ds
- push [bp+4]
- push [bp+6]
- push [bp+8]
- mov al,[bp+10]
- sub ah,ah
- push ax
- mov al,[bp+12]
- push ax
- L00: cmp _memory_model,0 ;check code model again
- jle L000 ;jump if near
- dec bp ;unadjust BP so all BP offsets same
- dec bp ;
- L000: pop depth ;set intermediate values
- pop width
- pop row_ofs
- pop col_ofs
- pop box_ofs
- pop row_seg
- pop col_seg
- pop box_seg
- mov ax,col_seg ;ES:DI pts to Col
- mov es,ax ;
- mov di,col_ofs ;
- sub cx,cx ;
- mov cl,es:[di] ;get column position
- jcxz I1 ;quit if column is zero
- dec cx ;count from zero
- mov ax,cx ;copy to AX
- add ax,width ;add width
- cmp ax,78 ;in range?
- jna J1 ;jump ahead if so
- I1: jmp T1 ;else quit routine
- J1: add cx,3 ;add 2 (+ inc) to col pos
- mov es:[di],cl ;change the setting
- sub cx,3 ;back to old col position
- mov ax,box_seg ;segment of Box
- mov es,ax ;load in ES
- mov di,box_ofs ;offset of Box
- mov ax,depth ;depth to AX
- dec ax ;dec for test
- cmp ax,24 ;in range?
- jna K1 ;jump ahead if so
- jmp T1 ;else quit routine
- K1: inc ax ;readjust
- mov bx,width ;width to BX
- dec bx ;dec for test
- cmp bx,79 ;in range?
- jna L1 ;jump ahead if so
- jmp T1 ;else quit
- L1: inc bx ;readjust
- mul bl ;width times depth
- shl ax,1 ;double for attributes
- add ax,di ;offset to end of Box
- mov endofbox,ax ;save end of box ptr
- mov di,ax ;pt ES:DI to end of Box
- mov ax,row_seg ;DS:SI pts to Row
- mov ds,ax ;
- mov si,row_ofs ;
- sub ax,ax ;
- mov al,[si] ;get row value
- dec ax ;count from zero
- cmp ax,24 ;in range?
- jna M1 ;jump ahead if so
- jmp T1 ;else quit
- M1: mov bl,160 ;bytes per row
- mul bl ;calculate row offset
- shl cx,1 ;col offset
- add ax,cx ;add to row offset
- mov si,ax ;SI pts to topleft corner
- mov toppos,si ;save it
- mov ax,dx ;_video_buffer
- mov ds,ax ;move to DS
- mov ax,width ;get width
- shl ax,1 ;double for attributes
- add si,ax ;DS:SI pts to topright
- mov rghtpos,si ;copy position
- cld ;set direction
- mov cx,depth ;get depth
- mov dx,si ;DX holds start col
- N1: mov si,dx ;set start col
- call Writeit ;write a char
- call Writeit ;write another
- add dx,160 ;forward one row
- loop N1 ;do next row
- mov ax,ds ;DS to AX
- mov es,ax ;now ES pts to screen too
- mov si,rghtpos ;top right position + 2
- sub si,2 ;minus 2
- mov di,si ;copy to DI
- add di,4 ;will shift right by 2
- std ;reverse direction flag
- cmp ax,0b800h ;graphics card?
- jb O1 ;jump if monochrome
- inc di ;forward ptr to start
- inc si ;other ptr
- O1: mov dx,depth ;depth
- mov ax,width ;width
- P1: mov cx,ax ;width to CX
- push di ;save target start
- push si ;save source start
- Q1: call Writeit ;write a char
- loop Q1 ;go do next
- pop si ;restore source start
- pop di ;restore target start
- add di,160 ;forward dest ptr
- add si,160 ;forward source ptr
- dec dx ;dec row counter
- jnz P1 ;loop till image shifted
- cld ;reset direction flag
- mov ax,box_seg ;segment of Box
- mov ds,ax ;move to DS
- mov si,box_ofs ;offset of Box
- mov di,toppos ;ES:DI pts to old topleft
- mov cx,depth ;get depth
- mov dx,width ;get width
- sub dx,2 ;minus 2 for 2 columns
- shl dx,1 ;double for attributes
- R1: call Writeit ;write a char
- call Writeit ;write another
- add di,156 ;forward target ptr
- add si,dx ;forward source ptr
- loop R1 ;do next row
- mov ax,box_seg ;segment of Box
- mov es,ax ;move to ES
- mov di,box_ofs ;offset of Box
- mov ax,col_seg ;segment of Col
- mov ds,ax ;move to DS
- mov si,endofbox ;offset of Col
- add di,4 ;DI to new start of Box
- mov cx,depth ;get depth
- S1: add di,dx ;forward target ptr
- movsw ;move one char of two
- movsw ;move the next
- loop S1 ;go move 2 more chars
- mov di,box_ofs ;offset to start of Box
- mov si,di ;copy to SI
- add si,4 ;SI 2 chars to the right
- mov ax,depth ;depth
- mov cx,width ;width
- mul cl ;size of Box
- mov cx,ax ;move to CX as counter
- rep movsw ;shift all downwards
- jmp short U1 ;jump to end
- T1: pop bx ;balance stack if error
- U1: sti ;reenable interrupts
- pop ds ;
- pop si ;
- pop di ;
- add sp,24 ;restore stack pointer
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _box_right endp
- Writeit PROC
- push dx ;save DX
- push ax ;save AX
- mov dx,es ;get target segment
- mov ax,ds ;get source segment
- cmp ax,dx ;is source larger?
- jna A1 ;jump if not
- mov dx,ax ;else use source
- A1: cmp byte ptr snow,0 ;protect against snow?
- je F1 ;jump ahead if not
- mov dx,3dah ;status byte address
- B1: in al,dx ;get status byte
- test al,1 ;test bit
- jnz B1 ;loop till 0
- C1: in al,dx ;get status byte
- test al,1 ;test bit
- jz C1 ;loop till 1
- movsb ;move a character
- D1: in al,dx ;get status byte
- test al,1 ;test bit
- jnz D1 ;loop till 0
- E1: in al,dx ;get status byte
- test al,1 ;test bit
- jz E1 ;loop till 1
- movsb ;move a character
- jmp short G1 ;jump ahead and quit
- F1: movsw ;move the character
- G1: pop ax ;restore AX
- pop dx ;restore DX
- ret ;
- Writeit endp
- _TEXT ENDS
- END